<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入easyui的样式 -->
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/default/easyui.css">
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/icon.css">
<!-- js文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
//页面加载时发送请求
$(function(){
	$('#hj').datagrid({
		url:"SelStudentJob",
		queryParams: {			
			sid:"${sessionScope.user.sid}",
		}
	});
});

$(function(){
	//更改底部工具栏 getPager返回页面对象
	var pager = $('#hj').datagrid('getPager');	
	  pager.pagination({
		pageList: [10,20,30],
	});
})

function formatOper(val,row,index){  
   return '<a href="#" onclick="editUser('+index+')">完成作业</a>';     
    }  
//提交作业
function editUser(index){  
    $('#hj').datagrid('selectRow',index);
    var row = $('#hj').datagrid('getSelected');  
    if (row){  
        $('#dlg').dialog('open').dialog('setTitle','学生完成作业');  
        $('#fm').form('load',row);  
        $('#jd').hide();        
		 var job =$("#hj").datagrid('getSelected');
		 $("#jrid").textbox('setValue',job.jrid);
		 $("#jname").textbox('setValue',job.jname);
		 $("#beginTime").textbox('setValue',job.beginTime);
		 $("#tname").textbox('setValue',job.tname);
		 $("#jsname").textbox('setValue',job.jsname);
		 $("#answer").textbox('setValue',"");
 	}
}
		 $(function(){
			 $("#ok").click(function(){				 
				 var jrid = $("#jrid").val();
				 var uid=${user.uid};
				 var answer=$("#answer").val();
				 if(answer!=""){
						$.ajax({	   				
			   				type:"post",
			   				url:"complete",
			   				data:{"answer":answer,"jrid":jrid,"uid":uid},
			   				dataType:"text",
			   				success:function(data){
					    		if(data=="true"){
					    			$.messager.alert('提示','作业提交成功','info',function(){
					    				$('#hj').datagrid('reload'); 
					    				$('#dlg').dialog('close')
						    			}); 			    							 	    					    			
					    		  }else{
					    			  $.messager.alert('提示','作业提交失败','info',function(){
						    				$('#hj').datagrid('reload'); 
					    			  });
					    		  }
					    	}    		   		
			    	}) 
				 }else {
					 $.messager.alert('提示','作业未完成','info',function(){
		    				$('#hj').datagrid('reload'); 
	    			  });
				 }
		 })
 })
 
</script>
<body>
	 <table id="hj" title="作业提交" class="easyui-datagrid" method="post"
            toolbar="#toolbar" pagination="true" fit="true"  
            striped="true"  pageSize="10"
            rownumbers="true" fitColumns="true" border="false">         
        <thead>
			<tr>
            	<th field="jrid" hidden="true" >作业记录编号</th>               
                <th field="jname" width="50" resizable="false">作业名字</th> 
                <th field="beginTime" width="50" resizable="false">布置作业时间</th>  
                <th field="tname" width="50" resizable="false">老师名字</th>
                <th field="jsname" width="50" resizable="false">作业状态 </th>
                <th data-options="field:'_operate',width:50,align:'center',formatter:formatOper">完成作业</th>
            </tr>
        </thead>
    </table> 
       <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div style="margin-left: 60px"> 
        <form id="fm" method="post" novalidate>
             <div class="fitem" id="jd">
                <label>作&nbsp业&nbsp&nbsp编&nbsp号:</label>
                <input id="jrid" class="easyui-textbox" disabled="true">
            </div>       
            <div class="fitem" id="na">
                <label>作&nbsp&nbsp业&nbsp&nbsp名&nbsp&nbsp字:</label>
                <input id="jname" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="ag">
                <label>布置作业时间:</label>
                <input id="beginTime" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="ad">
                <label>学&nbsp&nbsp生&nbsp&nbsp名&nbsp&nbsp字:</label>
                <input id="tname" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="nm">
                <label>完&nbsp&nbsp成&nbsp&nbsp状&nbsp&nbsp态:</label>
                <input id="jsname" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="un">
                <label>学&nbsp&nbsp生&nbsp&nbsp答&nbsp&nbsp案:</label>
                <input id="answer" class="easyui-textbox"
                required="required" missingMessage="请输入您的答案">
            </div>
        </form>
       </div>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" style="width:90px;" id="ok" >保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" 
        onclick="javascript:$('#dlg').dialog('close')" style="width:90px;">取消</a>
    </div>
</body>
</html>